var stepId = $CertusJsonAjax.getStepInstanceId();
var processId = $CertusJsonAjax.getProInstanceId();
$CertusFormAjax.ajax("findLcDemanList",{"processId":processId},function(response){
    var data = response.data;
    $$scope.dmNo = data.dm_no;
    $$scope.rproName = data.rproName;
    $$scope.proName = data.pro_name;
    $$scope.version = data.version;
    $$scope.proStage = data.pro_stage;
    if (data.pro_lv=="3"){
        $$scope.proLv = "高";
    }else if (data.pro_lv=="2"){
        $$scope.proLv = "中";
    }else{
        $$scope.proLv = "低";
    }

    if (data.dm_level=="3"){
        $$scope.dmLv = "高";
    }else if (data.dm_level=="2"){
        $$scope.dmLv = "中";
    }else{
        $$scope.dmLv = "低";
    }
    $$scope.deliverDate = data.deliver_date;
    $$scope.createUser = data.createUser;
    $$scope.createTime = data.createTime;
    $$scope.dmDesc = data.dm_desc;
    $$scope.riskRating = data.risk_rating;
    $$scope.id = data.id;

    $$scope.planPayDate = data.plan_pay_date;
    $$scope.deliverVersion = data.deliver_version;
    $$scope.mgRiskRating = data.mg_risk_rating;
    $$scope.reasonAnalyse = data.reason_analyse;
    $$scope.workRating = data.work_rating;
    $$scope.mgOpinionMsg = data.mg_opinion_msg;
});
$(".submit1").on('click',function () {
    if (!certusValidateNotnull()){
        return;
    }
    var arr =$("form").serializeArray();
    var data = {};
    for (var i=0;i<arr.length;i++){
        data[arr[i].name] = arr[i].value;
    };
    data.stepId = stepId;
    $CertusFormAjax.ajax("toXqxzSp",{"params":JSON.stringify(data)},function(response){
        layer.msg("提交成功");
        window.history.back();
    });
});

//审核不通过
$(".lcEnd").on('click',function () {
    var id = $("#dmLcId").val();
    $CertusFormAjax.ajax("shutDemanLc",{"stepId":stepId,"id":id},function(response){
        layer.msg("审批成功");
        window.history.back();
    });
});

$(".back").on('click',function () {
    var id = $("#dmLcId").val();
    var opinionMsg = $("#opinionMsg").val();
    if (opinionMsg==null||opinionMsg==""){
        alert("请填写审批意见");
        return;
    }
    $CertusFormAjax.ajax("rhXqsq",{"id":id,"stepId":stepId,"opinionMsg":opinionMsg},function(response){
        layer.msg("退回成功");
        window.history.back();
    })
})

//转他人分析
function tansOther() {
    if (!certusValidateNotnull()){
        return;
    }
    var id = $("#dmLcId").val();
    var mgUserId = $("#mgUserId").val();
    var tranDesc = $("#tranDesc").val();
    $CertusFormAjax.ajax("toTransferDeman",{"id":id,"stepId":stepId,"mgUserId":mgUserId,"tranDesc":tranDesc},function(response){
        layer.msg("转交成功");
        window.history.back();
    });
}
function hidebox(){
    $(".hidebox").hide();
}

//展示隐藏
function showbox() {
    $(".hidebox").show();
    $("#autocomplete1").focus();
    $CertusFormAjax.ajax("findSpUserList",{},function (response) {
        var nhlTeams = [];
        var data = response.data;
        for (var i=0;i<data.length;i++){
            var arr={};
            arr.name=data[i].userName+"["+data[i].positonName+"]";
            arr.id = data[i].userId;
            nhlTeams.push(arr);
        }
        //自动补全
        var nhl = $.map(nhlTeams, function (obj) {
            return {
                value: obj.name,
                data: { category: obj.id }
            };
        });
        // Initialize autocomplete with local lookup:
        $('#autocomplete1').devbridgeAutocomplete({
            lookup: nhl,
            minChars: 1,
            onSelect: function (suggestion) {
                $("#mgUserId").val(suggestion.data.category);
            },
            showNoSuggestionNotice: true,
            noSuggestionNotice: 'Sorry, no matching results'
        });
    });
};


$CertusFormAjax.ajax("findSpUserList",{},function (response) {
    var nhlTeams = [];
    var data = response.data;
    for (var i=0;i<data.length;i++){
        var arr={};
        arr.name=data[i].userName+"["+data[i].positonName+"]";
        arr.id = data[i].userId;
        nhlTeams.push(arr);
    }
    //自动补全
    var nhl = $.map(nhlTeams, function (obj) {
        return {
            value: obj.name,
            data: { category: obj.id }
        };
    });
    // Initialize autocomplete with local lookup:
    $('#autocomplete2').devbridgeAutocomplete({
        lookup: nhl,
        minChars: 1,
        onSelect: function (suggestion) {
            $("#jfUserId").val(suggestion.data.category);
        },
        showNoSuggestionNotice: true,
        noSuggestionNotice: 'Sorry, no matching results'
    });
});

$(".submitJF").on('click',function () {
    if (!certusValidateNotnull()){
        return;
    }
    var arr =$("form").serializeArray();
    var data = {};
    for (var i=0;i<arr.length;i++){
        data[arr[i].name] = arr[i].value;
    };
    data.stepId = stepId;
    $CertusFormAjax.ajax("toJfmgSp",{"params":JSON.stringify(data)},function(response){
        layer.msg("提交成功");
        window.history.back();
    });
});
$(".turnPrb").on('click',function () {
    var spUser = $("#jfUserId").val();
    var id = $("#dmLcId").val();
    if (id==null||id==""){
        alert("未找到审批人");
        return;
    }
    $CertusFormAjax.ajax("toTurnProb",{"id":id,"spUser":spUser,"stepId":stepId},function(response){
        layer.msg("提交成功");
        window.history.back();
    });
});

$(".transfer").on('click',function () {
    var tranDesc = $("#tranDesc").val();
    var mgUserId = $("#mgUserId").val();
    var id = $("#dmLcId").val();
    $CertusFormAjax.ajax("toTransferDeman",{"id":id,"stepId":stepId,"tranDesc":tranDesc,"mgUserId":mgUserId},function(response){
        layer.msg("提交成功");
        window.history.back();
    });
});
